<?
session_start();
require_once 'config.php';
if($_SESSION['cart']) {
   $arr_pro_id = $_SESSION['cart'];
   foreach($arr_pro_id as $key=>$value){
      $str_pro_id .= $key.',';
      $str_pro_number .= $value.',';
   }
   $str_pro_id = rtrim($str_pro_id,',');
   $str_pro_number = rtrim($str_pro_number,',');
   $products = db_array("SELECT * FROM products WHERE pro_id IN(".$str_pro_id.")");
}

$templateProduct = new TemplateProduct();
$id_field = 'ord_id';
$ord_date = time();
   $myform = new generate_form();
   $myform->add('ord_pro_id','pro_id_order',0,0,'',1,'',0,'');
   $myform->add('ord_pro_number', 'pro_number', 0, 0, '', 1, 'Bạn chưa nhập số lượng.', 0, '');
   $myform->add('ord_cus_phone','phone_contact',0,0,'',1,'Bạn chưa nhập số điện thoại',0);
   $myform->add('ord_cus_name','name_contact',0,0,'',1,'Bạn chưa nhập họ tên',0);
   $myform->add('ord_cus_address','address_contact',0,0,'',0,'',0);
   $myform->add('ord_cus_email', 'email_contact', 0, 0, '', 1, 'Bạn chưa nhập email', 0, '');
   $myform->add('ord_cus_note', 'content_contact', 0, 0, '', 0, '', 0, '');
   $myform->add('ord_date', 'ord_date', 1, 1, 0, 0, '', 0, '');
   $myform->addTable('orders');
   
   
   $action	= getValue('action', 'str', 'POST', '');
   if($action			==	'excute'){
      $errorMsg_res = '';
      $errorMsg_res		.=	$myform->checkdata();
         if($errorMsg_res == ''){
            $db_ex		=	new db_execute_return();
       			$last_id		=	$db_ex->db_execute($myform->generate_insert_SQL());
       			if($last_id	> 0){   		
       			  send_mailer('vattucongnghiepdonganh@gmail.com',"Khách hàng đặt mua mới",'Kiểm tra hệ thống để xem khách hàng đặt mua mới nhất',"");
    		         echo "<script>alert('Bạn đã đặt mua thành công !');</script>";
               }
    			
         }
   }
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <link type="image/x-icon" href="/favicon.ico" rel="icon" />
   
   <title></title>
   <meta name="description" content=""/>
   <meta name="keywords" content=""/>
   <meta name="AUTHOR" content="Vnupdate" />
   <meta name="COPYRIGHT" content="" />
   <meta name="ROBOTS" content="INDEX, FOLLOW" />
   <meta name="RATING" content="GENERAL" />
   
   <meta property="og:title" content="" />
   <meta property="og:type" content="website" />
   <meta property="og:url" content="" />
   <meta property="og:image" content="" />
   <meta property="og:site_name" content="" />
   <meta property="og:description" content="" />
   <meta property="fb:admins" content="" />
   <meta property="fb:app_id" content=""/> 
   <!-- css -->   
   <link rel="stylesheet" type="text/css" href="<?=TEMPLATE_PATH?>css/home.css" />	
   <link rel="stylesheet" type="text/css" href="<?=TEMPLATE_PATH?>css/order.css" />
   <!-- js -->
   <script type="text/javascript" src="<?=TEMPLATE_PATH?>js/jquery-1.9.0.min.js"></script>
   <script type="text/javascript" src="<?=TEMPLATE_PATH?>js/common.js"></script>
</head>
<body>   
   <? include('view/common/vic_header.php');?>
   <div class="global_container">
      <div class="slider">
         <?include('view/common/vic_slide.php')?>
      </div>
      <div class="content_wrap">
         <div class="content_left">
            <?include('view/common/vic_content_left.php')?>
            
         </div>
         <div class="content_right">
            <div class="products_hot_wrap">
               <h1 class="pro_hot_title">
                  Đặt mua giỏ hàng
               </h1>
               <div class="products_hot">
               <form action="" method="POST" onsubmit="return validSend();">
                  <table border="0" cellpadding="7px" cellspacing="4px" width="100%">
                     <tbody>
                        <tr>
                           <td class="tlabel">Lưu ý :</td>
                           <td class="tlabel" style="text-align: left">Bạn vui lòng nhập chính xác thông tin những ô có dấu <span class="imp">*</span></td>
                           
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Họ và tên</td>
                           <td><input id="name_contact" name="name_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel">Địa chỉ</td>
                           <td><input id="address_contact" name="address_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Điện thoại</td>
                           <td><input id="phone_contact" name="phone_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Email</td>
                           <td><input id="email_contact" name="email_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel">Ghi chú</td>
                           <td valign="top"><textarea id="content_contact" name="content_contact" class="ctext"></textarea></td>
                        </tr>
                        <tr>
                           <td class="tlabel">&nbsp;</td>
                           <td valign="top">
                              <input type="hidden" class="" name="action" value="excute"/>
                              <input type="hidden" class="" name="pro_id_order" value="<?=$str_pro_id?>"/>
                              <input type="hidden" class="" name="pro_number" value="<?=$str_pro_number?>"/>
                              <input type="submit" class="order_submit" name="order_submit" value="Gửi"/>
                              <input type="reset" class="order_reset" name="order_reset" value="Đặt lại"/>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </form>
               </div>
            </div>
         </div>
      </div>
      <?include('view/common/vic_social_networking.php');?>
   </div>
   <?include('view/common/vic_footer.php');?>
</body>
</html>
<script>
function validSend(){	
	if($('#name_contact').val()==''){
		alert('Hãy nhập họ và tên.');
		$('#name_contact').focus();
      return false;
	}
	if($('#phone_contact').val()==''){
		alert('Hãy nhập số điện thoại.');
		$('#phone_contact').focus();
      return false;
	}
	if(!isemail($('#email_contact').val())){
		alert('Hãy nhập Email liên hệ.');
		$('#email_contact').focus();
      return false;
	}
}
</script>